<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta charset="utf-8">
	<title></title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
	<meta name="description" content="">
	<meta name="author" content="">
	<!-- STYLESHEETS --><!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
	<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css" >
	<link rel="stylesheet" type="text/css"  href="../../css/themes/default.css" id="skin-switcher" >
	<link rel="stylesheet" type="text/css"  href="../../css/responsive.css" >
	
	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	
	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">

</head>
<body>
	<header class="navbar clearfix" id="header">
	</header>
	
	<!-- PAGE -->
	<section id="page">
				<!-- SIDEBAR -->
				<div id="sidebar" class="sidebar">
					<div class="sidebar-menu nav-collapse">
						
						<!-- SIDEBAR MENU -->
						<ul>							
							
						</ul>
						<!-- /SIDEBAR MENU -->
					</div>

				</div>
				<!-- /SIDEBAR -->
		<div id="main-content">
		<!-- 发货日期选择 -->
		<div class="modal fade" id="sales_time_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">设置上架时间</h4>
							</div>
							<div class="modal-body">
								<div class="form-group" style="margin-bottom: 0px">								   
									<div class="col-md-12">
										请设置上架时间，用于前台商品显示时排序
									</div>
								</div>
									<div class="form-group">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>上架时间：</label>
									<div class="col-md-4">
										<input class="Wdate" style="height:34px" type="text"  name="saleTime" onfocus="WdatePicker({maxDate:'#F{\'2030-10-01\'}',dateFmt:'yyyy-MM-dd'})">
									</div>
								</div>
							</div>
							
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
								<button type="button" class="btn btn-success bt-save">保存</button>
							</div>
						</div>
					</div>
				</div>
		<!-- end -->
			<!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
				<div class="modal fade" id="productComment_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">商品评价</h4>
							</div>
							<div class="modal-body">
							  <div class="form-group" style="margin-bottom: 5px">
									<label class="control-label col-md-3" style="line-height:34px;">商品名称：</label>
									<div class="col-md-8 productName" style="line-height:34px;">
										
									</div>
								</div>	
								 <div class="form-group" style="margin-bottom: 5px">
									<label class="control-label col-md-3" style="line-height:34px;">颜色：</label>
									<div class="col-md-4 color" style="line-height:34px;">
										
									</div>
								</div>								
								<div class="form-group" style="margin-bottom: 5px">
									<label class="control-label col-md-3" style="line-height:34px;">尺码：</label>
									<div class="col-md-4">
										<select  id="size_select" class="col-md-12 select2-offscreen" tabindex="-1">
																		
										</select>
									</div>
								</div>
								<div class="form-group" style="margin-bottom: 5px">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>评价日期：</label>
									<div class="col-md-4">
									<input class="Wdate" style="height:34px" type="text"  name="startTime" onfocus="WdatePicker({maxDate:'#F{\'2030-10-01\'}',dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false,readOnly:true})">
									</div>
								</div>
							    <div class="form-group" style="margin-bottom: 5px">
									<label class="control-label col-md-3" style="line-height:34px;">用户：</label>
									<div class="col-md-4">
										<select  id="userId_select" class="col-md-12 select2-offscreen" tabindex="-1">
										<option value='38'>一生一世</option>
										<option value='39'>小鱼妈妈</option>
										<option value='40'>小鸽子</option>
										<option value='41'>vivi</option>
										<option value='42'>lucy</option>
										<option value='43'>米格</option>
										<option value='44'>温仪</option>
										<option value='45'>快乐的苹果</option>
										<option value='46'>飞鸟</option>
										<option value='47'>常悦</option>
										<option value='25025'>豆豆妈</option>
										<option value='25026'>佳佳</option>
										<option value='25029'>可爱淘</option>
										<option value='25031'>黑糖玛奇朵</option>
										<option value='25033'>香草咖啡</option>
										<option value='25035'>甜甜圈</option>
										<option value='25038'>端端</option>
										<option value='25039'>小五家</option>
										<option value='25040'>houhou</option>
										<option value='25041'>迟迟</option>
										<option value='25045'>奔奔</option>
										<option value='25046'>归去</option>
										<option value='25048'>放开</option>
										<option value='25052'>后来</option>
										<option value='25053'>蓉蓉</option>
										</select>
									</div>
								</div>
								<div class="form-group" style="margin-bottom: 5px">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>标签：</label>
								    <div class="col-md-8">
										<label class="checkbox-inline"><input type="checkbox"  name="commentTag" value="很喜欢"/>很喜欢</label>
										<label class="checkbox-inline"><input type="checkbox"  name="commentTag" value="百搭"/>百搭</label>
										<label class="checkbox-inline"><input type="checkbox"  name="commentTag" value="颜色正"/>颜色正</label>
										<label class="checkbox-inline"><input type="checkbox"  name="commentTag" value="舒服"/>舒服</label>
										<label class="checkbox-inline"><input type="checkbox" name="commentTag" value="柔软"/>柔软</label>
										<label class="checkbox-inline" style="margin-left:0px;padding:0" >(最多选择3个)
										</label>												
									</div>	
									
								</div>
								<div class="form-group">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>评价：</label>
									<div class="col-md-4">
										<textarea cols="10" rows="3" name="content" class="form-control" style="width:280px;resize:none;" ></textarea>
										
									</div>
								</div>
							</div>
							<input name="productId" type="hidden">
							<div class="modal-footer" style="text-align: center;">
								<button type="button" class="btn btn-success bt-save" >仅保存</button>
								<button type="button" class="btn btn-success bt-save">保存并查看</button>
							</div>
						</div>
					</div>
				</div>
				<div class="modal fade" id="update_pre_sales_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">设置预售</h4>
							</div>
							<div class="modal-body">
								<div class="form-group">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>预售日期：</label>
									<div class="col-md-4">
										<input class="Wdate" style="height:34px" type="text"  name="preSaleDate" onfocus="WdatePicker({maxDate:'#F{\'2030-10-01\'}',dateFmt:'yyyy-MM-dd'})">
									</div>
								</div>
							</div>
							
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
								<button type="button" class="btn btn-success bt-save">保存</button>
							</div>
						</div>
					</div>
				</div>
				<div class="modal fade" id="update_price_config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">修改价格</h4>
							</div>
							<div class="modal-body">
							<div class="form-group">
							<input name=id type="hidden">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>商品名称：</label>
									<div class="col-md-4 " style="line-height:34px;">
										<input class="form-control" style="height:34px;width:350px;" type="text" name="productName" >
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>销售价：</label>
									<div class="col-md-4">
										<input class="form-control" style="height:34px" type="text" name="productSalePrice" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);">
									</div>
								</div>
								<div class="form-group" style="display: none">
									<label class="control-label col-md-3"  style="disline-height:34px; ">会员价：</label>
									<div class="col-md-4">
										<input class="form-control" style="height:34px" type="text" name="vipPrice" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);">
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-3" style="line-height:34px;">拼团价：</label>
									<div class="col-md-4">
										<input class="form-control" style="height:34px" type="text" name="promotionPrice" onkeypress="return $.IsDecimal(event);" onblur="return $.IsMoney(this);">
									</div>
								</div>
							 	<div class="form-group" style="display: none">
									<label class="control-label col-md-3" style="line-height:34px"><span class="required">*</span>分享返利：</label>
									<div class="col-md-4">
										<select id="shareRate_select" name="shareRate">
											<option></option>
									    	<option value="0.03">3%</option>
									    	<option value="0.05">5%</option>
									    	<option value="0.1">10%</option>
									  	</select>
										<span class="error-span"></span>
									</div>
								</div> 
								<div class="form-group">
									<label class="control-label col-md-12 required" style="line-height:34px;">所有尺码都会更新为当前价格，尺码价格不同请使用编辑功能</label>
									
								</div>
							</div>
							
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
								<button type="button" class="btn btn-success bt-updateprice">保存</button>
							</div>
						</div>
					</div>
				</div>
			<div class="container">
				<div class="row">
					<div id="content" class="col-lg-12">
						<!-- PAGE HEADER-->
						<div class="row">
							<div class="col-sm-12">
								<div class="page-header">
									<!-- STYLER -->
									
									<!-- /STYLER -->
									<!-- BREADCRUMBS -->
									<ul class="breadcrumb">
										<li>
											<i class="fa fa-home"></i>
											<a href="../index.html">首页</a>
										</li>
										<li>
											<a href="#">商品管理</a>
										</li>
										<li>商品列表</li>
									</ul>
									<!-- /BREADCRUMBS -->
									
								</div>
							</div>
						</div>
						<!-- /PAGE HEADER -->
						<!-- FORMS QUERY-->
						<div class="row">
							<div class="col-md-12">
								<div class="row">
									<div class="col-md-12">
										<div class="box border primary">
											<div class="box-title">
												<h4><i class="fa fa-bars"></i>查询条件</h4>
											</div>
											<div class="box-body big" style="padding:10px;">												
										<form class="form-horizontal" role="form" id="export" action="../../admin/product/exportProduct.do">
												  <div class="form-group mrg-bt10">
													<label class="col-sm-1 control-label" style="width: auto">商品名称：</label>
													<div class="col-sm-2">
													  <input type="text" class="form-control" name="productName" placeholder="输入关键字">
													</div>
													<label class="col-sm-1 control-label" style="width: auto">商品款式：</label>
													<div class="col-sm-2">
													<select id="group_select" name="groupId" class="col-md-12 select2-offscreen" tabindex="-1">
															
													</select>		
													</div>
													<label class="col-sm-1 control-label" for="e1" style="width: auto">商品状态：</label>
													<div class="col-sm-2">
															<select id="salesStatus" name="salesS"class="col-md-12 select2-offscreen" tabindex="-1">
															   <option value="-1">选择状态</option>
															   <option value="OnSale">上架</option>
															   <option value="InStock">下架</option>
															</select>												
													</div>
													<div class="col-sm-2" style="width: 120px">
													  <input type="checkbox"  name="special"><span style='margin-left:10px'>特例品</span>
													</div>
													<div class="col-sm-2" style="width: 120px;display: none">
													  <input type="checkbox"  name="preDate"><span style='margin-left:10px'>预售</span>
													</div>
												  </div>
												  <div class="form-group mrg-bt10">
												  	<label class="col-sm-1 control-label" style="width: auto">商品编号：</label>
													<div class="col-sm-2">
													  <input type="text" class="form-control" name="productCode" placeholder="输入关键字">
													</div>
												 <div class="col-sm-2 tuan" style="width: 120px">
												    <input type="checkbox"  name="isGroup"><span style='margin-left:10px'>是否拼团</span>
												 </div>
												 <div class="col-sm-2 tuan" style="width: 155px;display: none">
													<input type="checkbox"  name="vipPrice"><span style='margin-left:10px'>是否女王价</span>
												 </div>
														  <!--  <label class="col-sm-1 control-label" style="width: auto">所属店铺：</label>
															<div class="col-sm-2">
															  <select id="supplier_select" name="supplierId" style="width: 100%"></select>
															</div> -->
													<div class="col-sm-1">
									       				<a class="btn btn-primary search">查询</a>
													</div>
												  </div>
												 </form>
											</div>
										</div>
									</div>
								</div>		
						    </div>
						</div>
						<!-- /FORMS QUERY -->
						<div class="row" style="height: 30px;">
								<div class="col-md-12">
									<div class="box ">
										<a href="add_product.html"  class="btn btn-success config">
											<i class="fa  fa-plus-square-o"></i> 新增商品
										</a>
										<a href="javascript:;"  class="btn btn-warning export">
											<i class="fa  fa-copy"></i> 导出商品
										</a>
									</div>
								</div>
					    </div>
							
					    <div class="row">
								<!-- TABLES -->
								<div class="col-md-12">
									<!-- BOX -->
									<div class="box border primary">
										<div class="box-title">
											<h4><i class="fa fa-table"></i>商品数：<span id="total"></span>条 </h4>
										</div>
										<div class="box-body">
											<table id="db_product_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
												
											</table>
										</div>
									</div>
									<!-- /BOX -->
								</div>
							</div>
							<!-- /TABLES -->
						
						
						<div class="footer-tools">
							<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
						</div>
					</div><!-- /CONTENT-->
				</div>
			</div>
		</div>
	</section>
	<!--/PAGE -->
	<!-- JAVASCRIPTS -->
	<!-- Placed at the end of the document so the pages load faster -->
	<!-- JQUERY -->
	<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
	<!-- JQUERY UI-->
	<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
	<!-- BOOTSTRAP -->
	<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
	<!-- BLOCK UI -->
	<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>

	<!-- AUTOSIZE -->
	<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
	<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
	<!-- DATA TABLES -->
		<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
		<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

	<!-- INPUT MASK -->
	<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
    <!--bootbox-->
	<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
	<!-- SELECT2 -->
	<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	<!-- UNIFORM -->
	<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
	 <script language="javascript" type="text/javascript" src="../../js/My97DatePicker/WdatePicker.js"></script>
	<!-- COOKIE -->
	<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
	<!-- CUSTOM SCRIPT -->
	<script src="../../js/script.js"></script>
	<script src="../../js/common.js"></script>
		<script>		
		var Product=function(){
	         var  $mainDataTable=null,id=null,status=null;
	         var deleteProduct=function(){
	          		var tr = $(this).closest("tr");
					if ($(tr).find(".saleStatus").html() != "下架") {
						$.alert("请先下架再删除！");
						return;
					} else {
							$.confirm("确认删除此商品?",function(){
								$.ajax({
										type: "post",
										url: App.getContextPath()+"admin/product/updateProductStatus.do",
										async: true,
										data: {
											id: $(tr).find(".id").html()
										},
										success: function(result) {
											searchProduct();
										}
									});
								});
					}
	         };
	         var updatePreSales=function(){
	        	 var productId = $(this).attr("id");
	        	 var preSaleDate = $(this).attr("preSaleDate");
	        		if(preSaleDate != null && preSaleDate !='null'){
	        			$("#update_pre_sales_config").find("input").val($.getLocalDate(preSaleDate));
	        		}else{
	        			$("#update_pre_sales_config").find("input").val("");
	        			
	        		}
	        		$("#update_pre_sales_config").modal("show");
	       		$(".bt-save").unbind("click").click(function(){
	       			
	       			var preSaleDate =$("#update_pre_sales_config").find("input").val();
		        	 $.ajax({
		        		 type: "get",
							url: App.getContextPath()+"admin/product/updatePreSaleDate.do",
							async: true,
							data: {id:productId,preSaleDate:$("[name=preSaleDate]").val()},
							success: function(result) {
								if(result.type =="success"){
	        						$("#update_pre_sales_config").modal("hide");
									$.alert("修改成功");
								}else{
	        						$("#update_pre_sales_config").modal("hide");
									$.alert("修改失败");
								}		
								searchProduct();
							}
		        		 
		        	 });
	        	 });
	         }
	         //添加商品评价
	          var showProductComment=function(){
	        	  var date=new Date();
				  $("[name=startTime]").val(date.format("yyyy-MM-dd hh:mm:ss"));
	        	  var tr = $(this).closest("tr");	
	        	  $(".productName").html($(this).attr("productName"));
	        	
	        	  $(".color").html($(tr).find(".color").html());
	        	  $("[name=productId]").val($(tr).find(".id").html())
	        	  $("[name=content]").val("");
	        	 //获取产品的尺码
	        	 $.ajax({
	        		 type: "post",
						url: App.getContextPath()+"admin/product/getSkuByProductId.do",
						async: true,
						data: {productId:$(tr).find(".id").html()},
						success: function(result) {
							var option="";
							if(result!=null){
								$.each(result,function(index,item){
									option+="<option value='"+item.id+"'>"+item.sizeName+"</option>";
								});
							$("#size_select").empty().append(option).select2();	
			 					$("#userId_select").select2();			
							$("#productComment_config").modal("show");
							$(".bt-save").unbind("click").click(addProductComment);
							}
							
						}
	        		 
	        	 });
	        	 
	        	 
	         }
	         var addProductComment=function(){
	        	 var that=$("#productComment_config");
	        	 var index=$(this).index();
	        	 
	        	 var tags=[];
	        	 $("input[type=checkbox]:checked").each(function(){
	        		 tags.push($(this).val());
					})
	        	 if(tags.length==0){
	        		 $.alert("请选择评价标签");
	        		 return false;
	        	 }
	        	 if(tags.length>3){
	        	 	 $.alert("评价标签最多选择3个");
	        		 return false;
	        	 }
	        	 if($("[name=content]").val().trim().length==0){
	        		 $.alert("请输入评价内容");
	        		 return false;
	        	 }
	        	 var p={};		
	        	  p.orderId=0;
	        	  p.productId=$(that).find("[name=productId]").val();
	        	  
	        	  p.skuId=$("#size_select").val();
	        	  p.userId=$("#userId_select").val();;
	        	  p.content=$("[name=content]").val();
	        	  p.commentTag=tags.toString();
	        	  
				   $.ajax({
								type: "post",
								url: App.getContextPath()+"admin/productComment/addProductComment.do",
								async: true,
								data: $.param({productComment:JSON.stringify(p),createTime:$("[name=startTime]").val()}),
								success: function(result) {
									$("#productComment_config").modal("hide");
									if(index==1)
										window.location.href="../publish/product_comment.html?name="+$(".productName").html();
								}
						});
						
	         }
	         //更新销售价和商品名称
	         var updatePrice=function(){
	        	 $("#update_price_config").find("[name=productSalePrice]").val($(this).attr("productSalePrice"));
	        	 $("#update_price_config").find("[name=vipPrice]").val($(this).attr("vipPrice"));
	        	 $("#update_price_config").find("[name=promotionPrice]").val($(this).attr("promotionPrice")=='null'?'0':$(this).attr("promotionPrice"));
	        	 $("#update_price_config").find("[name=id]").val($(this).attr("id"));
				 $("#shareRate_select").select2("val",$(this).attr("shareRate"));
	        	 //$("#update_price_config").find(".productName").html();
	        	 $("#update_price_config").find("[name=productName]").val($(this).closest("tr").find(".productName").html());
	        	$("#update_price_config").modal("show");
	        	$(".bt-updateprice").unbind().click(function(){
	        		if($("#update_price_config").find("[name=productName]").val().trim().length==0){
	        		 $.alert("请输入商品名称");
	        		 return false;
	        	    }
	        	/* 	var shareRate = $("#update_price_config").find("[name=shareRate]").val();
	        		if(shareRate==null||shareRate==''){
	        			$.alert("请选择分享返利");
	        			return false;
	        		} */
	        		var p={};
	        		p.id= $("#update_price_config").find("[name=id]").val();
	        		p.productSalePrice= $("#update_price_config").find("[name=productSalePrice]").val();
	        		p.productName= $("#update_price_config").find("[name=productName]").val();
	        		p.vipPrice=$("#update_price_config").find("[name=vipPrice]").val();
	        		p.promotionPrice=$("#update_price_config").find("[name=promotionPrice]").val();
	        		p.shareRate=0.05;
	        		$.ajax({
						type: "post",
						url: App.getContextPath()+"admin/product/updateSalesPrice.do",
						async: true,
						data: $.param({product:JSON.stringify(p)}),
						success: function(result) {
							$.alert("更新成功");
							$("#update_price_config").modal("hide");
							searchProduct();
						
						}
				});
	        	});
	         }
	         //设置为特里品
	         var siteSpecial=function(){
	        	 var productId = $(this).attr("id");
	        	 var isSpecial = $(this).attr("isSpecial");
	        	 var content ;
	        	 if(isSpecial == 'true'){
	        		 content = "是否取消特例品";
	        		 isSpecial = false;
	        	 }else{
	        		 content = "是否将该商品设置为特例品";
	        		 isSpecial = true;
	        		 
	        	 }
	        	 
					$.confirm(content,function(){
						$.ajax({
								type: "get",
								url: App.getContextPath()+"admin/product/siteSpecial.do",
								async: true,
								data: {
									id: productId,isSpecial : isSpecial
								},
								success: function(result) {
									if(result.type == 'error'){
										$.alert(result.content)
									}
									
									searchProduct();
								}
							});
					
	        	});
	         }
	         
	         
	         var searchProduct=function(){
	              var groupId=$("#group_select").val();	  
	              var status=$("#salesStatus").val();	   
	              var q=$("#export").find("input[name=productName]").val();      
	              var productNumber=$("input[name=productCode]").val();      
	              var special=$("[name=special]").prop("checked");
	              var supplierId=$("#supplier_select").val();
	              
	              var url=App.getContextPath()+"admin/product/searchProduct.do?q="+q+"&isSpecial="+special+"&productCode="+productNumber+"&isGroup="+$("[name=isGroup]").prop("checked")+"&preSaleDate="+$("[name=preDate]").prop("checked");
	                  if(supplierId!=null)
	                	  url+="&supplierId="+supplierId;
		              if(groupId!=-1&&groupId!=null)
		                  url+="&groupId="+groupId;
		              if(status!=-1&&status!=null)
		                  url+="&productStatus="+status
		              if($("#export").find("[name=vipPrice]").prop("checked"))
		            	  url+="&vipPrice=100";
		              else
		            	  url+="&vipPrice=0";
		              
	                 
			       if($mainDataTable){
			           $mainDataTable.api().ajax.url(url).load();	   		
		   		       return;	
			        }
		           var dtSetting = $.dataTableSetting({					
							"ajaxSource" :url,
							"serverSide" : true,
							"bFilter" : false,// 去掉搜索框
							"bLengthChange" : true,// 每页显示数量							
							"sScrollX":"100%",
							"sScrollXInner": "100%",
							"iDisplayLength": 25,
							
							"bSort" : false,					
							"aoColumns" : [ {
								"mDataProp" : "id",
								"sTitle" : "商品ID",
								"width" : "7%"	
							},{						
								"mDataProp" : "productCode",
								"sTitle" : "商品编码",
								"width" : "10%",
								"class":"productCode"							
							}, {
								"mDataProp" : "productName",
								"sTitle" : "商品名称",
								"width" : "23%",
								"render":function(data, type, row){
								if(row.productImages!=null){
								  var data=row.productImages[0];
								  var price=row.productSalePrice.toFixed(2);
								  var sourceprice=row.productOriginalPrice;
								  if(row.promotionPrice>0){
									  price+="(拼团价:"+row.promotionPrice.toFixed(2)+")";
								  }
								  if(row.vipPrice>0){
									  price+="(会员价:"+row.vipPrice.toFixed(2)+")";
								  }
								  var preDate="";
								  if(row.preSaleDate!=null)
									  preDate="<br><span class='text-danger'>预售期："+$.getLocalDate(row.preSaleDate)+"</span>";
								  								  
								  if(data!=null)							
								  return "<div style='display: inline-flex'><div><img width=100 height=100 src="+getProductImage(data.imagePath,"-200*200.jpg")+"></div><div><a href='"+App.getDomain()+"/product/product.html?productId="+row.id+"' target='_blank'>"+row.productName+"</a><br><span class='text-danger'>￥"+price+" 原价："+sourceprice+"</span>"+preDate+"</div></div>";
								}
								return "";
								}
							}, {						
								"sTitle" : "商品分类",
								"mDataProp" : "categoryName",
								"width" : "9%"								
							}	
							, {		
							    "mDataProp" : "groupName",				
								"sTitle" : "商品款式 ",
								"width" : "10%"									
							}							
							, {			
							   "mDataProp" : "saleStatus",					
								"sTitle" : "状态",
								"width" : "7%",
								"class" : "saleStatus",
								"render":function(data, type, row){
								    return row.saleStatus=="OnSale"?"上架":"下架";
								       
								}
									
							}, {
								"mDataProp" : "createTime",
								"sTitle" : "创建时间",
								"width" : "8%",
								"render":function(data, type, row){
								    return $.getLocalTime(row.createTime);
								}
							}, {
								"mDataProp" : "updateTime",
								"sTitle" : "发布时间",
								"width" : "8%",
								"class":"saleTime",
								"render":function(data, type, row){
								if(row.saleTime!=null)
								   return $.getLocalTime(row.saleTime);
								   return ""; 
								}
							}, {						
								"sTitle" : "操作",
								"render":function(data, type, row) {
							     var str="<p class='btn-toolbar' style='margin:0px'>";
							     if(row.saleStatus=="InStock")
							    	 str+="<a class='btn btn-warning btn-xs bt_sales btn-width' style='width:80px;margin-left:0px;margin-right:5px;margin-top:2px;'><i class='fa "+(row.saleStatus=="OnSale"?"fa-arrow-circle-o-down":"fa-arrow-circle-o-up")+"'></i>"+(row.saleStatus=="OnSale"?"下架":"上架")+"</a>";
							     if(row.saleStatus=="OnSale")
							    	 str+="<a class='btn btn-warning btn-xs bt_sales btn-width' style='width:80px;margin-left:0px;margin-right:5px;margin-top:2px;'><i class='fa "+(row.saleStatus=="OnSale"?"fa-arrow-circle-o-down":"fa-arrow-circle-o-up")+"'></i>"+(row.saleStatus=="OnSale"?"下架":"上架")+"</a>";
								     
							    	 str+="<a target='_blank' class='btn btn-success btn-xs bt_edit btn-width' style='width:80px;margin-left:0px;margin-right:5px;margin-top:2px;' href='add_product.html?id="+row.id+"&flag=edit'><i class='fa fa-pencil-square-o'></i>编辑</a>";
							    	 str+="<a target='_blank' class='btn btn-danger btn-xs bt_del btn-width' style='width:80px;margin-left:0px;margin-right:5px;margin-top:2px;'><i class='fa fa-trash-o'></i> 删除</a>";
							    	 str+="<a target='_blank' class='btn btn-primary btn-xs bt_add btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' href='add_product.html?id="+row.id+"&flag=group'><i class='fa fa-copy'></i>添加同款</a>";
							    	 str+="<a class='btn btn-purple btn-xs btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' href='add_product.html?id="+row.id+"&flag=copy'><i class='fa fa-thumbs-up icon-white'></i>复制商品</a>";							 
								
									// str+="<a class='btn btn-info btn-xs bt_product_pre_sales btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;' id='"+row.id+"' preSaleDate='"+row.preSaleDate+"'><i class='fa fa-thumbs-up icon-white'></i>预售管理</a>";
									 str+="<a class='btn btn-grey btn-xs bt_price btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;'  id='"+row.id+"' productSalePrice='"+row.productSalePrice+"' vipPrice='"+row.vipPrice+"' promotionPrice='"+row.promotionPrice+"' shareRate='"+row.shareRate+"'><i class='fa fa-thumbs-up icon-white'></i>一键改价</a>";
									 str += "<a class='btn btn-primary btn-xs bt_special btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;'  id='"+row.id+"' isSpecial='"+row.isSpecial+"'><i class='fa fa-copy'></i>设置特例品</a>";
									// str += "<a class='btn btn-primary btn-xs bt_productComment btn-width' style='margin-left:0px;margin-right:5px;margin-top:2px;'  id='"+row.id+"' productName='"+row.productName+"'><i class='fa fa-copy'></i>商品评价</a>";
									 
									 str += "</p>"
								 return str;
								}
							},{
								"mDataProp" : "id",
								"class" : "id hide"								
							},{
								"mDataProp" : "saleStatus",
								"class" : "salesStatus hide"							
							},{
								"mDataProp" : "productName",
								"class" : "productName hide"							
							},{
								"mDataProp" : "shortName",
								"class" : "color hide"							
							},{
								"mDataProp" : "productSalePrice",
								"class" : "productSalePrice hide"							
							}]
						});
					
				      $mainDataTable = $("#db_product_list").dataTable(dtSetting);
	         };
	       
	         var updateSaleTime=function(time){
	        	 $.ajax({
						type: "post",
						url: App.getContextPath()+"admin/product/updateSalesStatus.do",
						async: true,
						data: {
							id: id,
							saleStatus:status=="OnSale"?"InStock":"OnSale",
						    saleTime:time
						},
						success: function(result) {
							$("#sales_time_config").modal("hide");
							searchProduct();
						}
					});
	         }
	         var loadSupplier = function() {
					$.ajax({
						type: "get",
						url: App.getContextPath() + "admin/store/searchSupplierList.do",
						async: true,
						success: function(result) {
							if (result!=null) {
								var data = eval(result);
								var option = "<option value=''>选择店铺</option>";
								$.each(data, function(index, item) {
									option += "<option value='" + item.id + "'>" + item.supplierName + "</option>";
								});
								$("#supplier_select").empty().append(option).select2();
							}
						}
					});
				};
	         return {
	         
	         init:function(){
	             $.ajax({
					type: "post",
					url: App.getContextPath()+"admin/group/searchGroupList.do",
					async: true,			
					success: function(result) {
						if(result!=null)
						{ 
										
							var option="<option value=''>选择款式</option>";
							$.each(result,function(index,item){								
								 option+="<option value='"+item.id+"'>"+item.groupName+"</option>";
							});
							$("#group_select").empty().append(option).select2({placeholder: "选择款式"});
							
						}
						
					}
				});
	        
	           $("#salesStatus").select2({placeholder: "选择状态"});
	         //  loadSupplier();        
	           $("#shareRate_select").select2({placeholder: "选择分享返利"});
	           
	             $(".search").click(searchProduct);	    
	         	 $("#db_product_list").on("click",".bt_sales",function() {
		         	  status=$(this).closest("tr").find(".salesStatus").html();
		         	 var txt=status=="OnSale"?"下架":"上架";
		         	  id=$(this).closest("tr").find(".id").html();
		         	 
		         	 if(status=="InStock"&&$(this).closest("tr").find(".saleTime").html()!=""){
		         		 $("#sales_time_config").modal("show");
		         		$("#sales_time_config").find(".bt-save").off("click").on("click",function(){
		         			var t=$("#sales_time_config").find("[name=saleTime]").val();
		         			if(t==""){
		         				$.alert("请选择上架时间");
		         				return false;
		         			}
		         			updateSaleTime(t);
		         			
		         		});
		         		 
		         	 }else{
		         	 $.confirm("确认执行"+txt+"操作?",function(){
		         		updateSaleTime(null);
		         	 
		         	 }); 
		         	 }
				});
	         
	          $("#db_product_list").on("click",".bt_del",deleteProduct);
	          $("#db_product_list").on("click",".bt_productComment",showProductComment);
	          $("#db_product_list").on("click",".bt_product_pre_sales",updatePreSales);
	          $("#db_product_list").on("click",".bt_price",updatePrice);
	          $("#db_product_list").on("click",".bt_special",siteSpecial);
	          
	          searchProduct();
	          $(".export").click(function(){$("#export").submit();});
	          
	          }
		    }
	      }();
	      
	      $(function(){
	      	$("#header").load("../head.html");
	      	 $("#sidebar").load("../menu.html");
	      	
	        App.init(); //Initialise plugins and elements	        
	      	Product.init();
	      	
	      });
		</script>
		<!-- /JAVASCRIPTS -->
</body>
</html>